<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'Power.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<script src="<%=basePath%>web/js/jquery.min.js"></script>
    <script src="<%=basePath%>web/js/jquery.easyui.min.js"></script>
    <script src="<%=basePath%>web/js/easyui-lang-zh_CN.js"></script>
    <link rel="stylesheet" href="<%=basePath%>web/themes/icon.css">
    <link rel="stylesheet" href="<%=basePath%>web/themes/default/easyui.css">
    <link rel="stylesheet" href="<%=basePath%>web/css/wu.css">
	<script>
	//此处是easyui的json格式
		var tree = {
			id:'',
			text:'',
			state:'',
			checked:'',
			attributes:'',
			children:''
		}
		//此处是把后台传过来的json数据转成easyui规定的格式
		function bl(item){
			var tree = new Object();
			tree.id = item.id;
			tree.text = item.modelname;
			//tree.state = 'open';
			if(item.permission==1){
				tree.checked = true;
			}else{
				tree.checked = false;
			}
			tree.attributes = item.url;
			if(item.child!= null){
				tree.children = jsonbl(item.child);
			}else{
				tree.children = [];
			}
			return tree;
		}
		function jsonbl(data){
			var easyTree = [];
			$.each(data,function(index,item){
			 easyTree[index] = bl(item);
			 });
			return easyTree;
		}


	
	
	$(function(){
	var rid=$("#rid").val();
		$('#tt').tree({    
    		url:'/kxmanage/power/show?rid='+rid,
    		checkbox:true,
    		loadFilter: function(data){
				return jsonbl(data); 
			}   
		});  
	});
	function show(){
		var aa=[];
		var x=$("#tt").tree("getChecked")
		for(var i=0;i<x.length;i++){
			aa.push(x[i].id);
		}
		var a=JSON.stringify(aa);
		var rid=$("#rid").val();
		$.ajax({
			url:"/kxmanage/power/update",
			type:"post",
			dataType:"json",
			data:{"rid":rid,"a":a},
			success:function(data){
				if(data.result=="success"){
					alert("修改成功");
				}else{
					alert("修改失败");
				}
			}
		});
	}
	</script>
  </head>
  
  <body>
  <button onclick="show()">保存</button>
  <input type="hidden" id="rid" value="${rid}"/>
    <ul id="tt"></ul> 
  </body>
</html>
